package com.dcw.lixb.designmode.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lixiaobin
 * @date 2020-07-22 15:01:14
 * @desc 组合模式  像Android中的View ViewGroup 各种子view就是组合模式
 */
public class Employee {
    private String name;
    private String dept;
    private int salary;
    private List<Employee> subordinates;

    public Employee(String name, String dept, int salary) {
        this.name = name;
        this.dept = dept;
        this.salary = salary;
        subordinates = new ArrayList<>();
    }

    public void addSubordinate(Employee employee) {
        if (!subordinates.contains(employee)) {
            subordinates.add(employee);
        }
    }

    public boolean removeSubordinate(Employee employee) {
        return subordinates.remove(employee);
    }

    public List<Employee> getSubordinates() {
        return subordinates;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", dept='" + dept + '\'' +
                ", salary=" + salary +
                ", subordinates=" + subordinates +
                '}';
    }
}
